package ca.concordia.soen6461.wichf.navigation.view;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import ca.concordia.soen6461.wichf.controller.Event;
import ca.concordia.soen6461.wichf.controller.View;
import ca.concordia.soen6461.wichf.dao.PatientCartDao;
import ca.concordia.soen6461.wichf.entity.PatientCart;
import ca.concordia.soen6461.wichf.entity.ScheduledEvent;
import ca.concordia.soen6461.wichf.entity.User;

public class CartView implements View<CartView.Bean> {

	public static class Bean {

		private ArrayList<Appointment> appointments = new ArrayList<Appointment>();

		public ArrayList<Appointment> getAppointments() {
			return appointments;
		}
		
	}

	public static class Appointment {

		private int item;
		private String date;
		private String type;
		private Integer price;

		public int getItem() {
			return item;
		}

		public void setItem(int item) {
			this.item = item;
		}

		public String getDate() {
			return date;
		}

		public void setDate(String date) {
			this.date = date;
		}

		public String getType() {
			return type;
		}

		public void setType(String type) {
			this.type = type;
		}

		public Integer getPrice() {
			return price;
		}

		public void setPrice(Integer price) {
			this.price = price;
		}
	}
	
	private PatientCartDao patientCartDao;

	public CartView(PatientCartDao patientCartDao) {
		this.patientCartDao = patientCartDao;
	}

	@Override
	public Bean render(Event event) {
		DateFormat format = new SimpleDateFormat("MMM dd - HH:mm");
		Bean bean = new Bean();
		User user = event.getSession().get(User.class);
		PatientCart cart = patientCartDao.get(user);
		if (cart != null) {
			for (ScheduledEvent appointment : cart.getAppointments()) {
				Appointment a = new Appointment();
				a.setDate(format.format(appointment.getFrom()));
				a.setPrice(appointment.getType().getPrice());
				a.setType(appointment.getType().getDescription());
				bean.getAppointments().add(a);
			}
		}
		return bean;
	}

}
